package com.cloudkinto.service.order;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.service.IService;
import com.cloudkinto.bo.order.OrderVdfQueryBo;
import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;
import com.cloudkinto.entity.OrderAmazonVdfDo;
import com.cloudkinto.entity.ShopDo;
import com.cloudkinto.service.order.vo.amazon.vdfOrder.VdfOrderEntity;
import com.cloudkinto.service.orderoutput.openapivo.OpenApiOrderOutputAddReq;
import com.cloudkinto.service.orderoutput.vo.OrderOutputAddReq;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Retryable;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 亚马逊供应商api订单 供应商直接供货
 * </p>
 *
 * @author ding
 * @since 2024-06-19
 */
public interface OrderAmazonVdfService extends IService<OrderAmazonVdfDo> {

    Object add(Object req, Long userId);

    Object update(Object updateVo, Long userId);

    int delete(Long id, Long userId);

    Object detail(Long id);

    PageResult getListPage(OrderVdfQueryBo bo);

    void insertVdf(List<VdfOrderEntity> vendorOrderEntityList, Long shopId, Long companyId);

    SingleResult markSendOut(List<Long> ids, Long userId);

    SingleResult sendOut(String[] orderids, Long userId, Long companyId, boolean b);

    SingleResult sendOutNopackage(String orderid, Long userId, Long companyId);

    SingleResult sendOutMatch(List<OrderOutputAddReq> orderOutputAddReqList, Long userId);

    void vdfOrderSync(Long shopId, Date beforeDate, Date afterDate);

    SingleResult pageInit(Long companyId);

    /**
     * 导出发货标签文件
     * <p>
     * 导出的文档为A5竖排放置一个面单的pdf
     * vertical
     *
     * @param ids      订单id
     * @param response 响应
     */
    void exportShippingLabelVerticalA5Pdf(List<Long> ids, HttpServletResponse response);

    /**
     * 创建面单
     * 一件商品一个包裹
     * 已弃用
     *
     * @param purchaseOrderNumberList 采购单号
     * @param isOverwrite             是否覆盖原有的面单信息(需要分包时使用)
     * @return vdf订单id
     */
    @Deprecated
    Map<String, Object> createShippingLabel(List<String> purchaseOrderNumberList, boolean isOverwrite);

    void getVdfShippingLabel(
            Map<String, Long> purchaseAndShopIdMap,
            boolean isCreateLabel,
            boolean isOverwrite
    ) throws RuntimeException;

    void updateOrderSendOut(String platformNumber);


    @Retryable(
            value = RuntimeException.class,
            maxAttempts = 6,
            backoff = @Backoff(delay = 10000, multiplier = 2)
    )
    void getCreatLabelsStatus(ShopDo shopDo, String transactionId) throws RuntimeException;

    /**
     * 返回在指定时间范围内创建的客户发票列表
     */
    void getCustomerInvoices(Long shopId, Date beforeDate, Date afterDate);

    /**
     * 刷新分包信息
     *
     * @param purchaseOrderNumber
     * @return 返回面单及运输单号
     */
    JSONArray refreshShippingLabel(String purchaseOrderNumber);

    /**
     * 创建面单
     * 一件商品一个包裹
     *
     * @param purchaseOrderNumberList 采购单号
     * @param isOverwrite             是否覆盖原有的面单信息(需要分包时使用)
     * @return vdf订单id
     */
    Map<String, Object> createShippingLabelV2(List<String> purchaseOrderNumberList, boolean isOverwrite);

    OrderAmazonVdfDo addByOrderOutput(OpenApiOrderOutputAddReq req, Long companyId, Long shopId);
}
